<html>

<head>
<meta name=标题 content="">
<meta name=关键词 content="">
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 15 (filtered)">
<style>
<!--
 /* Font Definitions */
@font-face
	{font-family:"Courier New";
	panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Times;
	panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:DengXian;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:"\@DengXian";}
@font-face
	{font-family:"Microsoft YaHei";
	panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
	{font-family:Menlo;
	panose-1:2 11 6 9 3 8 4 2 2 4;}
@font-face
	{font-family:"\@Microsoft YaHei";}
 /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	font-size:12.0pt;
	font-family:DengXian;}
code
	{font-family:Courier;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	text-indent:21.0pt;
	font-size:12.0pt;
	font-family:DengXian;}
p.a, li.a, div.a
	{margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	line-height:200%;
	font-size:12.0pt;
	font-family:"Microsoft YaHei";}
.MsoChpDefault
	{font-family:DengXian;}
 /* Page Definitions */
@page WordSection1
	{size:595.0pt 842.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	layout-grid:15.6pt;}
div.WordSection1
	{page:WordSection1;}
 /* List Definitions */
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
-->
</style>

</head>

<body lang=ZH-CN style='text-justify-trim:punctuation'>

<div class=WordSection1 style='layout-grid:15.6pt'>

<p class=MsoNormal style='line-height:200%'><b><span lang=EN-US
style='font-size:14.0pt;line-height:200%;font-family:"Microsoft YaHei"'>mkswap</span></b></p>

<p class=MsoNormal align=left style='margin-bottom:12.0pt;text-align:left;
text-indent:21.0pt;line-height:200%;text-autospace:none'><span
style='font-family:"Microsoft YaHei";color:black;vertical-align:sub'>在<span
lang=EN-US>Linux</span>设备或者文件中创建交换分区，创建完成之后必须使用<span lang=EN-US>swapon</span>来使用它。一般在“<span
lang=EN-US>/etc/fstab</span>”中有一个交换分区列表，这样开机的时候就可以使用它。</span></p>

<p class=MsoNormal align=left style='margin-bottom:12.0pt;text-align:left;
text-indent:21.0pt;line-height:200%;text-autospace:none'><span
style='font-family:"Microsoft YaHei";color:black;vertical-align:sub'>此命令的适用范围：<span
lang=EN-US>RedHat</span>、<span lang=EN-US>RHEL</span>、<span lang=EN-US>Ubuntu</span>、<span
lang=EN-US>CentOS</span>、<span lang=EN-US>SUSE</span>、<span lang=EN-US>openSUSE</span>、<span
lang=EN-US>Fedora</span>。</span></p>

<p class=MsoNormal style='line-height:200%'><b><span lang=EN-US
style='font-family:"Microsoft YaHei"'>1</span></b><b><span style='font-family:
"Microsoft YaHei"'>、语法</span></b></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><b><span
lang=EN-US style='font-family:"Microsoft YaHei"'>mkswap  [-c]  [-f]  [-p PSZ]  [-L
label]  [-U uuid]  device  [size]</span></b></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>参数<span lang=EN-US>device</span>通常是一个磁盘分区<span
lang=EN-US>(</span>类似于<span lang=EN-US>/dev/sdb7)</span>，但也可以是一个文件。<span
lang=EN-US>Linux</span>内核不查看分区<span lang=EN-US>ID</span>，但是许多安装脚本将假定十六进制类型<span
lang=EN-US>82(Linux_SWAP)</span>的分区是交换分区。<span lang=EN-US>(</span>警告：<span
lang=EN-US>Solaris</span>也使用此类型。小心不要关闭<span lang=EN-US>Solaris</span>分区。<span
lang=EN-US>)</span></span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>参数<span lang=EN-US>size</span>是多余的，但为了向后兼容性而保留</span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>PSZ</span><span
style='font-family:"Microsoft YaHei"'>参数指定要使用的页大小。指定它几乎是不必要的<span lang=EN-US>(</span>甚至是不明智的<span
lang=EN-US>)</span>，但是某些旧的<span lang=EN-US>libc</span>版本是关于页面大小的，所以<span
lang=EN-US>mkswap</span>有可能弄错了它。症状是后续<span lang=EN-US>Swapon</span>失败了，因为没有找到交换签名。<span
lang=EN-US>PSZ</span>的典型值为<span lang=EN-US>4096</span>或<span lang=EN-US>8192</span>。</span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal style='line-height:200%'><b><span lang=EN-US
style='font-family:"Microsoft YaHei"'>2</span></b><b><span style='font-family:
"Microsoft YaHei"'>、选项列表</span></b></p>

<table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 width="95%"
 style='width:95.0%;margin-left:24.1pt;border-collapse:collapse;border:none'>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>选项</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border:solid windowtext 1.0pt;
  border-left:none;background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>说明</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-c</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>创建交换分区之前，检测坏块。如果有，那么打印出数量。</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-f</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>强制执行。如果没有此选项，<span
  lang=EN-US>mkswap</span>将拒绝擦除带有分区表的设备上的第一个块或整个磁盘上的第一个块<span lang=EN-US>(</span>例如<span
  lang=EN-US>/dec/sda)</span>。</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-p</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>设置页大小，默认<span
  lang=EN-US>4096</span>。一般是不需要指定这个参数的</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-L label</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>指定一个<span
  lang=EN-US>label</span>，方便<span lang=EN-US>swapon</span>使用。只适用于新的风格交换区域</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-v1</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>创建<span
  lang=EN-US>v1</span>版本的<span lang=EN-US>swap</span>分区，<span lang=EN-US>2.5</span>内核之后只支持这种的</span></p>
  </td>
 </tr>
 <tr>
  <td width="28%" valign=top style='width:28.58%;border:solid windowtext 1.0pt;
  border-top:none;padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>-U uuid</span></p>
  </td>
  <td width="71%" valign=top style='width:71.42%;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:0cm 5.4pt 0cm 5.4pt'>
  <p class=MsoNormal style='line-height:200%'><span style='font-family:"Microsoft YaHei"'>指定<span
  lang=EN-US>uuid</span>，默认情况会生成<span lang=EN-US>uuid</span></span></p>
  </td>
 </tr>
</table>

<p class=MsoNormal style='line-height:200%'><span lang=EN-US style='font-family:
"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal style='line-height:200%'><b><span lang=EN-US
style='font-family:"Microsoft YaHei"'>3</span></b><b><span style='font-family:
"Microsoft YaHei"'>、说明</span></b></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>交换头不触及第一个块。引导加载程序或磁盘标签可以在那里，但不建议安装。建议的设置是为<span
lang=EN-US>Linux</span>交换区域使用单独的分区。<span lang=EN-US>mkswap</span>和许多其他类似<span
lang=EN-US>mkfs</span>的实用程序一样，擦除了第一块，这样就可以删除磁盘上的旧系统。<span lang=EN-US>mkswap</span>拒绝擦除带有磁盘标签的设备上的第一个块，或者整个磁盘。</span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>交换区域的最大有用大小取决于体系结构和内核版本，在<span
lang=EN-US>i386</span>、<span lang=EN-US>PPC</span>、<span lang=EN-US>m68k</span>、<span
lang=EN-US>ARM</span>、<span lang=EN-US>sparc</span>上为<span lang=EN-US>1 GiB</span>、<span
lang=EN-US>MIPS</span>上为<span lang=EN-US>512 MiB</span>、<span lang=EN-US>alpha</span>上为<span
lang=EN-US>128 GiB</span>、<span lang=EN-US>sparc64</span>上为<span lang=EN-US>3
TiB</span>。对于<span lang=EN-US>2.3.3</span>以后的内核来说，没有这样的限制。请注意，在<span
lang=EN-US>2.1.117</span>之前，内核为每个页面分配了一个字节，而现在它分配了两个字节，因此使用中的交换区域<span
lang=EN-US>2 GIB</span>可能需要<span lang=EN-US>2</span>个<span lang=EN-US>MIB</span>内核内存。</span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>目前，<span lang=EN-US>Linux</span>允许<span
lang=EN-US>32</span>个交换区域<span lang=EN-US>(</span>这是<span lang=EN-US>Linux2.4.10</span>之前的<span
lang=EN-US>8</span>个<span lang=EN-US>)</span>。使用中的区域可以在文件“<span lang=EN-US>/proc/swaps</span>”中看到<span
lang=EN-US>(</span>自<span lang=EN-US>2.1.25</span>以来<span lang=EN-US>)</span>。<span
lang=EN-US>mkswap</span>拒绝<span lang=EN-US>10</span>页以下的区域。如果您不知道您的机器使用的页面大小，您可能可以使用<span
lang=EN-US>“cat /proc/cpuinfo”</span>查找它。</span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>若要设置交换文件，必须在使用<span lang=EN-US>mkswap</span>初始化该文件之前创建该文件，例如使用以下命令：</span></p>

<table class=a0 border=1 cellspacing=0 cellpadding=0 width="95%"
 style='width:95.0%;margin-left:24.1pt;border-collapse:collapse;border:none'>
 <tr style='height:14.9pt'>
  <td width=836 valign=top style='width:836.15pt;border:solid windowtext 1.0pt;
  background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt;height:14.9pt'>
  <p class=MsoNormal style='line-height:200%'><span lang=EN-US
  style='font-family:"Microsoft YaHei"'>    # dd if=/dev/zero of=swapfile
  bs=1024 count=65536</span></p>
  </td>
 </tr>
</table>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
style='font-family:"Microsoft YaHei"'>注意，交换文件不能包含任何漏洞<span lang=EN-US>(</span>因此，使用<span
lang=EN-US>cp(1)</span>创建该文件是不可接受的<span lang=EN-US>)</span></span></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal style='line-height:200%'><b><span lang=EN-US
style='font-family:"Microsoft YaHei"'>4</span></b><b><span style='font-family:
"Microsoft YaHei"'>、实例</span></b></p>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>1</span><span
style='font-family:"Microsoft YaHei"'>）创建交换分区，指定页大小<span lang=EN-US>2048</span></span></p>

<table class=a0 border=1 cellspacing=0 cellpadding=0 width="95%"
 style='width:95.0%;margin-left:24.1pt;border-collapse:collapse;border:none'>
 <tr style='height:123.2pt'>
  <td width=836 valign=top style='width:836.15pt;border:solid windowtext 1.0pt;
  background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt;height:123.2pt'>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>[root@localhost
  ~]# <b>mkswap -p 2048 /dev/sdb4           //</b></span></code><code><b><span
  style='font-size:10.0pt;line-height:200%;font-family:DengXian'>这里指定页大小</span></b></code><code><b><span
  lang=EN-US style='font-size:10.0pt;line-height:200%;font-family:Menlo'>2048</span></b></code><code><b><span
  style='font-size:10.0pt;line-height:200%;font-family:DengXian'>，取代了系统默认的</span></b></code><code><b><span
  lang=EN-US style='font-size:10.0pt;line-height:200%;font-family:Menlo'>4096</span></b></code></p>
  <p class=MsoNormal style='line-height:200%'><code><b><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>Using user-specified
  page size 2048, instead of the system value 4096</span></b></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>Setting up
  swapspace version 1, size = 16382 KiB</span></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>no label,
  UUID=42f07b0e-0adb-47b6-a906-1209efabb981</span></code></p>
  </td>
 </tr>
</table>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>2</span><span
style='font-family:"Microsoft YaHei"'>）创建交换分区，指定页大小<span lang=EN-US>4096</span>，指定<span
lang=EN-US>label</span></span></p>

<table class=a0 border=1 cellspacing=0 cellpadding=0 width="95%"
 style='width:95.0%;margin-left:24.1pt;border-collapse:collapse;border:none'>
 <tr style='height:14.9pt'>
  <td width=836 valign=top style='width:836.15pt;border:solid windowtext 1.0pt;
  background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt;height:14.9pt'>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>[root@localhost
  ~]# <b>mkswap -p 4096 -L wj /dev/sdb4    //</b></span></code><code><b><span
  style='font-size:10.0pt;line-height:200%;font-family:DengXian'>笔者当前的系统，不能使用</span></b></code><code><b><span
  lang=EN-US style='font-size:10.0pt;line-height:200%;font-family:Menlo'>2048</span></b></code><code><b><span
  style='font-size:10.0pt;line-height:200%;font-family:DengXian'>大小的页</span></b></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>Setting up
  swapspace version 1, size = 16380 KiB</span></code></p>
  <p class=MsoNormal style='line-height:200%'><code><b><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>LABEL=wj,</span></b></code><code><span
  lang=EN-US style='font-size:10.0pt;line-height:200%;font-family:Menlo'>
  UUID=c458a15d-50ee-4e10-a49b-b59add4879d5</span></code></p>
  </td>
 </tr>
</table>

<p class=MsoNormal style='text-indent:21.0pt;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>3</span><span
style='font-family:"Microsoft YaHei"'>）使用交换分区</span></p>

<table class=a0 border=1 cellspacing=0 cellpadding=0 width="95%"
 style='width:95.0%;margin-left:24.1pt;border-collapse:collapse;border:none'>
 <tr style='height:14.9pt'>
  <td width=836 valign=top style='width:836.15pt;border:solid windowtext 1.0pt;
  background:#E7E6E6;padding:0cm 5.4pt 0cm 5.4pt;height:14.9pt'>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>[root@localhost
  ~]# <b>swapon /dev/sdb4           //</b></span></code><code><b><span
  style='font-size:10.0pt;line-height:200%;font-family:DengXian'>使用指定的分区</span></b></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>[root@localhost
  ~]# <b>swapon </b></span></code><code><b><span lang=EN-US style='font-size:
  10.0pt;line-height:200%;font-family:Helvetica'>–</span></b></code><code><b><span
  lang=EN-US style='font-size:10.0pt;line-height:200%;font-family:Menlo'>s                  
  //</span></b></code><code><b><span style='font-size:10.0pt;line-height:200%;
  font-family:DengXian'>查看分区使用情况</span></b></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>Filename             Type       Size   Used   Priority</span></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>/dev/dm-1             
  partition  2940920    0   -1</span></code></p>
  <p class=MsoNormal style='line-height:200%'><code><span lang=EN-US
  style='font-size:10.0pt;line-height:200%;font-family:Menlo'>/dev/sdb4             
  partition  16376  0   -2</span></code></p>
  </td>
 </tr>
</table>

<p class=MsoNormal style='line-height:200%'><span lang=EN-US style='font-family:
"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal style='line-height:200%'><span lang=EN-US style='font-family:
"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal style='line-height:200%'><span lang=EN-US style='font-family:
"Microsoft YaHei"'>&nbsp;</span></p>

<p class=MsoNormal align=center style='text-align:center;line-height:200%'><span
lang=EN-US style='font-family:"Microsoft YaHei"'>Copyright@david 
zhytwj2018@163.com</span></p>

</div>

</body>

</html>
